package com.tywj.lib.core.common.util

import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable
import androidx.annotation.*
import androidx.core.content.ContextCompat

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/7
 *     desc   : 资源工具类
 *     version: 1.0.0
 * </pre>
 */
object ResourcesUtil {

    val resources: Resources by lazy { AppUtil.context.resources }

    fun getColor(@ColorRes id: Int): Int = ContextCompat.getColor(AppUtil.context, id)

    fun getBitmap(id: Int): Bitmap = BitmapFactory.decodeResource(resources, id)

    fun getDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.getDrawable(AppUtil.context, id)

    fun getString(@StringRes id: Int): String = resources.getString(id)

    fun getStringArray(@ArrayRes id: Int): Array<String> = resources.getStringArray(id)

    fun getDimension(@DimenRes id: Int): Float = resources.getDimension(id)

    fun getDimensionPixelOffset(@DimenRes id: Int): Int = resources.getDimensionPixelOffset(id)

    fun getDimensionPixelSize(@DimenRes id: Int): Int = resources.getDimensionPixelSize(id)

    fun getInterger(@IntegerRes id: Int) = resources.getInteger(id)
}